package com.example.zzl.model.HomeFragment;

import android.content.Context;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
import com.example.zzl.model.BaseModel;
import com.example.zzl.model.bean.Home;
import com.example.zzl.model.cans.HomeUrl;
import com.example.zzl.utils.specification.VolleySingleton;
import com.example.zzl.viewmodel.BaseViewModel;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by ligg on 2017/2/11.
 */

public class HotSpecialModel extends BaseModel implements Response.Listener<String> {

    public List<Home.Special.ResultBean> getList() {
        return list;
    }

    private List<Home.Special.ResultBean> list;

    public HotSpecialModel(Context context, BaseViewModel callback) {
        super(context, callback);
    }

    @Override
    public void loadData(String parameter) {
        StringRequest stringRequest = new StringRequest(HomeUrl.hotSpecial + parameter, this, VolleySingleton.volleySingleton);
        VolleySingleton.volleySingleton.getRequestQueue().add(stringRequest);
    }

    @Override
    public void onResponse(String response) {
        Type type = new TypeToken<List<Home.Special.ResultBean>>() {
        }.getType();
        list = new Gson().fromJson(response, type);
        callback.loadFinished();
    }

}
